<template>
  <div class="PInfo">
    <van-nav-bar @click-left="onClickLeft" left-arrow title="公司信息">
      <van-button @click="setInfo" size="mini" slot="right" type="info">保存</van-button>
    </van-nav-bar>
    <!-- info -->
    <van-cell-group>
      <van-cell is-link title="头像">
        <template slot="right-icon">
          <img :src="info.src" alt class="pic" />
        </template>
      </van-cell>
      <van-field
        v-model="info.name"
        required
        clearable
        label="我的公司"
        right-icon="question-o"
        placeholder="我的公司"
        @click-right-icon="$toast('question')"
      />
      <van-field
        v-model="info.gangwei"
        required
        clearable
        label="招聘岗位"
        right-icon="question-o"
        placeholder="招聘岗位"
        @click-right-icon="$toast('question')"
      />
      <van-field
        v-model="info.time"
        required
        clearable
        label="工作时间"
        right-icon="question-o"
        placeholder="工作时间"
        @click-right-icon="$toast('question')"
      />
      <van-field
        v-model="info.weixin"
        required
        clearable
        label="工作要求"
        right-icon="question-o"
        placeholder="工作要求"
        @click-right-icon="$toast('question')"
      />
      <van-field
        v-model="info.year"
        required
        clearable
        label="工作年限"
        right-icon="question-o"
        placeholder="工作年限"
        @click-right-icon="$toast('question')"
      />
      <van-field
        v-model="info.youshi"
        required
        clearable
        label="年龄要求"
        right-icon="question-o"
        placeholder="年龄要求"
        @click-right-icon="$toast('question')"
      />
    </van-cell-group>
  </div>
</template>
<script>
export default {
  data: () => ({
    info: {}
  }),
  created () {
    this.getname()
    this.setInfo1() // 页面加载时调用localStorage的数据
    this.hhh()
  },
  methods: {
    async getname () {
      const res = await this.$http.get(
        '/gtename/' + localStorage.getItem('user')
      )
      const {
        data: { data, status }
      } = res
      if (status !== 1) return this.$Toast('拉取错误')
      this.info = data[0]
    },
    // 切换牛人身份接口
    async hhh () {
      const res = await this.$http.get(
        '/gangwei'
      )
      const {
        data: { data, status }
      } = res
      console.log(res)

      if (status !== 1) return this.$Toast('拉取错误')
      // this.info = data[0]
    },
    onClickLeft () {
      this.$router.go(-1)
    },
    // 保存公司信息
    async setInfo () {
      const res = await this.$http.post(
        '/gtename/' + localStorage.getItem('user'),
        this.info
      )
      const list = (res.config.data)
      // console.log(JSON.parse(list))
      const {
        data: { data, msg, status }
      } = res
      if (status !== 1) return this.$Toast(msg)
      this.$Toast(msg)
      localStorage.setItem('jianli', list)
      setTimeout(() => {
        // 跳转到人才首页页面
        this.$router.push('/personnel')
      }, 1500)
    },
    async setInfo1 () {
      const res = await this.$http.post(
        '/gtename/' + localStorage.getItem('user'),
        this.info
      )
      const list = (res.config.data)
      const {
        data: { data, msg, status }
      } = res
      if (status !== 1) return this.$Toast(msg)
      localStorage.setItem('jianli', list)
    }

  }
}
</script>
<style lang="less" scoped>
.PInfo {
  padding-bottom: 50px;
  .pic {
    width: 50px;
    height: 50px;
    border-radius: 50%;
  }
}
</style>
<style scoped>
.PInfo >>> .van-button--mini {
  background: #4dd599;
  display: inline-block;
  min-width: 57px;
  height: 30px;
  font-size: 15px;
  line-height: 23px;
}
.PInfo >>> .van-button--info {
  color: #fff;
  border: 1px solid #eee;
}
</style>
